home *** CD-ROM | disk | FTP | other *** search
/ 3D Game Programming All in One / 3D Game Programming All in One Disc.iso / 3D2E / demo / client / scripts / optionsDlg.cs < prev    next >
Encoding:
Text File  |  2005-11-23  |  15.6 KB  |  567 lines

  1.  
  2. function OptionsDlg::onWake(%this)
  3. {
  4.    OptGraphicsButton.performClick();
  5.    %buffer = getDisplayDeviceList();
  6.    %count = getFieldCount( %buffer );
  7.    OptGraphicsDriverMenu.clear();
  8.    OptScreenshotMenu.init();
  9.    OptScreenshotMenu.setValue($pref::Video::screenShotFormat);
  10.    for(%i = 0; %i < %count; %i++)
  11.       OptGraphicsDriverMenu.add(getField(%buffer, %i), %i);
  12.    %selId = OptGraphicsDriverMenu.findText( $pref::Video::displayDevice );
  13.     if ( %selId == -1 )
  14.         %selId = 0; // How did THAT happen?
  15.     OptGraphicsDriverMenu.setSelected( %selId );
  16.     OptGraphicsDriverMenu.onSelect( %selId, "" );
  17.  
  18.    // Audio 
  19.    OptAudioUpdate();
  20.    OptAudioVolumeMaster.setValue($pref::Audio::masterVolume);
  21.    OptAudioVolumeShell.setValue( $pref::Audio::channelVolume[$GuiAudioType]);
  22.    OptAudioVolumeSim.setValue(   $pref::Audio::channelVolume[$SimAudioType]);
  23.    OptAudioDriverList.clear();
  24.    OptAudioDriverList.add("OpenAL", 1);
  25.    OptAudioDriverList.add("none", 2);
  26.    %selId = OptAudioDriverList.findText($pref::Audio::driver);
  27.     if ( %selId == -1 )
  28.         %selId = 0; // How did THAT happen?
  29.     OptAudioDriverList.setSelected( %selId );
  30.     OptAudioDriverList.onSelect( %selId, "" );
  31.     
  32.     OptRemapList.fillList();
  33. }
  34.  
  35. function OptionsDlg::onSleep(%this)
  36. {
  37.    // write out the control config into the demo/client/config.cs file
  38.    moveMap.save( "demo/client/config.cs" );
  39.  
  40. }
  41.  
  42. function OptGraphicsDriverMenu::onSelect( %this, %id, %text )
  43. {
  44.     // Attempt to keep the same res and bpp settings:
  45.     if ( OptGraphicsResolutionMenu.size() > 0 )
  46.         %prevRes = OptGraphicsResolutionMenu.getText();
  47.     else
  48.         %prevRes = getWords( $pref::Video::resolution, 0, 1 );
  49.  
  50.     // Check if this device is full-screen only:
  51.     if ( isDeviceFullScreenOnly( %this.getText() ) )
  52.     {
  53.         OptGraphicsFullscreenToggle.setValue( true );
  54.         OptGraphicsFullscreenToggle.setActive( false );
  55.         OptGraphicsFullscreenToggle.onAction();
  56.     }
  57.     else
  58.         OptGraphicsFullscreenToggle.setActive( true );
  59.  
  60.     if ( OptGraphicsFullscreenToggle.getValue() )
  61.     {
  62.         if ( OptGraphicsBPPMenu.size() > 0 )
  63.             %prevBPP = OptGraphicsBPPMenu.getText();
  64.         else
  65.             %prevBPP = getWord( $pref::Video::resolution, 2 );
  66.     }
  67.  
  68.     // Fill the resolution and bit depth lists:
  69.     OptGraphicsResolutionMenu.init( %this.getText(), OptGraphicsFullscreenToggle.getValue() );
  70.     OptGraphicsBPPMenu.init( %this.getText() );
  71.  
  72.     // Try to select the previous settings:
  73.     %selId = OptGraphicsResolutionMenu.findText( %prevRes );
  74.     if ( %selId == -1 )
  75.         %selId = 0;
  76.     OptGraphicsResolutionMenu.setSelected( %selId );
  77.  
  78.     if ( OptGraphicsFullscreenToggle.getValue() )
  79.     {
  80.         %selId = OptGraphicsBPPMenu.findText( %prevBPP );
  81.         if ( %selId == -1 )
  82.             %selId = 0;
  83.         OptGraphicsBPPMenu.setSelected( %selId );
  84.         OptGraphicsBPPMenu.setText( OptGraphicsBPPMenu.getTextById( %selId ) );
  85.     }
  86.     else
  87.         OptGraphicsBPPMenu.setText( "Default" );
  88.  
  89. }
  90.  
  91. function OptGraphicsResolutionMenu::init( %this, %device, %fullScreen )
  92. {
  93.     %this.clear();
  94.     %resList = getResolutionList( %device );
  95.     %resCount = getFieldCount( %resList );
  96.     %deskRes = getDesktopResolution();
  97.  
  98.    %count = 0;
  99.     for ( %i = 0; %i < %resCount; %i++ )
  100.     {
  101.         %res = getWords( getField( %resList, %i ), 0, 1 );
  102.  
  103.         if ( !%fullScreen )
  104.         {
  105.             if ( firstWord( %res ) >= firstWord( %deskRes ) )
  106.                 continue;
  107.             if ( getWord( %res, 1 ) >= getWord( %deskRes, 1 ) )
  108.                 continue;
  109.         }
  110.  
  111.         // Only add to list if it isn't there already:
  112.         if ( %this.findText( %res ) == -1 )
  113.       {
  114.             %this.add( %res, %count );
  115.          %count++;
  116.       }
  117.     }
  118. }
  119.  
  120. function OptGraphicsFullscreenToggle::onAction(%this)
  121. {
  122.    Parent::onAction();
  123.    %prevRes = OptGraphicsResolutionMenu.getText();
  124.  
  125.    // Update the resolution menu with the new options
  126.    OptGraphicsResolutionMenu.init( OptGraphicsDriverMenu.getText(), %this.getValue() );
  127.  
  128.    // Set it back to the previous resolution if the new mode supports it.
  129.    %selId = OptGraphicsResolutionMenu.findText( %prevRes );
  130.    if ( %selId == -1 )
  131.        %selId = 0;
  132.      OptGraphicsResolutionMenu.setSelected( %selId );
  133. }
  134.  
  135.  
  136. function OptGraphicsBPPMenu::init( %this, %device )
  137. {
  138.     %this.clear();
  139.  
  140.     if ( %device $= "Voodoo2" )
  141.         %this.add( "16", 0 );
  142.     else
  143.     {
  144.         %resList = getResolutionList( %device );
  145.         %resCount = getFieldCount( %resList );
  146.       %count = 0;
  147.         for ( %i = 0; %i < %resCount; %i++ )
  148.         {
  149.             %bpp = getWord( getField( %resList, %i ), 2 );
  150.  
  151.             // Only add to list if it isn't there already:
  152.             if ( %this.findText( %bpp ) == -1 )
  153.          {
  154.                 %this.add( %bpp, %count );
  155.             %count++;
  156.          }
  157.         }
  158.     }
  159. }
  160.  
  161. function OptScreenshotMenu::init( %this )
  162. {
  163.    if( %this.findText("PNG") == -1 )
  164.       %this.add("PNG", 0);
  165.    if( %this.findText("JPEG") == - 1 )
  166.       %this.add("JPEG", 1);
  167. }
  168.  
  169. function optionsDlg::applyGraphics( %this )
  170. {
  171.     %newDriver = OptGraphicsDriverMenu.getText();
  172.     %newRes = OptGraphicsResolutionMenu.getText();
  173.     %newBpp = OptGraphicsBPPMenu.getText();
  174.     %newFullScreen = OptGraphicsFullscreenToggle.getValue();
  175.     $pref::Video::screenShotFormat = OptScreenshotMenu.getText();
  176.  
  177.     if ( %newDriver !$= $pref::Video::displayDevice )
  178.     {
  179.         setDisplayDevice( %newDriver, firstWord( %newRes ), getWord( %newRes, 1 ), %newBpp, %newFullScreen );
  180.         //OptionsDlg::deviceDependent( %this );
  181.     }
  182.     else
  183.         setScreenMode( firstWord( %newRes ), getWord( %newRes, 1 ), %newBpp, %newFullScreen );
  184. }
  185.  
  186.  
  187.  
  188. $RemapCount = 0;
  189. $RemapName[$RemapCount] = "Forward";
  190. $RemapCmd[$RemapCount] = "moveforward";
  191. $RemapCount++;
  192. $RemapName[$RemapCount] = "Backward";
  193. $RemapCmd[$RemapCount] = "movebackward";
  194. $RemapCount++;
  195. $RemapName[$RemapCount] = "Strafe Left";
  196. $RemapCmd[$RemapCount] = "moveleft";
  197. $RemapCount++;
  198. $RemapName[$RemapCount] = "Strafe Right";
  199. $RemapCmd[$RemapCount] = "moveright";
  200. $RemapCount++;
  201. $RemapName[$RemapCount] = "Turn Left";
  202. $RemapCmd[$RemapCount] = "turnLeft";
  203. $RemapCount++;
  204. $RemapName[$RemapCount] = "Turn Right";
  205. $RemapCmd[$RemapCount] = "turnRight";
  206. $RemapCount++;
  207. $RemapName[$RemapCount] = "Look Up";
  208. $RemapCmd[$RemapCount] = "panUp";
  209. $RemapCount++;
  210. $RemapName[$RemapCount] = "Look Down";
  211. $RemapCmd[$RemapCount] = "panDown";
  212. $RemapCount++;
  213. $RemapName[$RemapCount] = "Jump";
  214. $RemapCmd[$RemapCount] = "jump";
  215. $RemapCount++;
  216. $RemapName[$RemapCount] = "Fire Weapon";
  217. $RemapCmd[$RemapCount] = "mouseFire";
  218. $RemapCount++;
  219. $RemapName[$RemapCount] = "Adjust Zoom";
  220. $RemapCmd[$RemapCount] = "setZoomFov";
  221. $RemapCount++;
  222. $RemapName[$RemapCount] = "Toggle Zoom";
  223. $RemapCmd[$RemapCount] = "toggleZoom";
  224. $RemapCount++;
  225. $RemapName[$RemapCount] = "Free Look";
  226. $RemapCmd[$RemapCount] = "toggleFreeLook";
  227. $RemapCount++;
  228. $RemapName[$RemapCount] = "Switch 1st/3rd";
  229. $RemapCmd[$RemapCount] = "toggleFirstPerson";
  230. $RemapCount++;
  231. $RemapName[$RemapCount] = "Chat to Everyone";
  232. $RemapCmd[$RemapCount] = "toggleMessageHud";
  233. $RemapCount++;
  234. $RemapName[$RemapCount] = "Message Hud PageUp";
  235. $RemapCmd[$RemapCount] = "pageMessageHudUp";
  236. $RemapCount++;
  237. $RemapName[$RemapCount] = "Message Hud PageDown";
  238. $RemapCmd[$RemapCount] = "pageMessageHudDown";
  239. $RemapCount++;
  240. $RemapName[$RemapCount] = "Resize Message Hud";
  241. $RemapCmd[$RemapCount] = "resizeMessageHud";
  242. $RemapCount++;
  243. $RemapName[$RemapCount] = "Show Scores";
  244. $RemapCmd[$RemapCount] = "showPlayerList";
  245. $RemapCount++;
  246. $RemapName[$RemapCount] = "Animation - Wave";
  247. $RemapCmd[$RemapCount] = "celebrationWave";
  248. $RemapCount++;
  249. $RemapName[$RemapCount] = "Animation - Salute";
  250. $RemapCmd[$RemapCount] = "celebrationSalute";
  251. $RemapCount++;
  252. $RemapName[$RemapCount] = "Suicide";
  253. $RemapCmd[$RemapCount] = "suicide";
  254. $RemapCount++;
  255. $RemapName[$RemapCount] = "Toggle Camera";
  256. $RemapCmd[$RemapCount] = "toggleCamera";
  257. $RemapCount++;
  258. $RemapName[$RemapCount] = "Drop Camera at Player";
  259. $RemapCmd[$RemapCount] = "dropCameraAtPlayer";
  260. $RemapCount++;
  261. $RemapName[$RemapCount] = "Drop Player at Camera";
  262. $RemapCmd[$RemapCount] = "dropPlayerAtCamera";
  263. $RemapCount++;
  264. $RemapName[$RemapCount] = "Bring up Options Dialog";
  265. $RemapCmd[$RemapCount] = "bringUpOptions";
  266. $RemapCount++;
  267.  
  268.  
  269. function restoreDefaultMappings()
  270. {
  271.    moveMap.delete();
  272.    exec( "~/scripts/default.bind.cs" );
  273.    OptRemapList.fillList();
  274. }
  275.  
  276. function getMapDisplayName( %device, %action )
  277. {
  278.     if ( %device $= "keyboard" )
  279.         return( %action );        
  280.     else if ( strstr( %device, "mouse" ) != -1 )
  281.     {
  282.         // Substitute "mouse" for "button" in the action string:
  283.         %pos = strstr( %action, "button" );
  284.         if ( %pos != -1 )
  285.         {
  286.             %mods = getSubStr( %action, 0, %pos );
  287.             %object = getSubStr( %action, %pos, 1000 );
  288.             %instance = getSubStr( %object, strlen( "button" ), 1000 );
  289.             return( %mods @ "mouse" @ ( %instance + 1 ) );
  290.         }
  291.         else
  292.             error( "Mouse input object other than button passed to getDisplayMapName!" );
  293.     }
  294.     else if ( strstr( %device, "joystick" ) != -1 )
  295.     {
  296.         // Substitute "joystick" for "button" in the action string:
  297.         %pos = strstr( %action, "button" );
  298.         if ( %pos != -1 )
  299.         {
  300.             %mods = getSubStr( %action, 0, %pos );
  301.             %object = getSubStr( %action, %pos, 1000 );
  302.             %instance = getSubStr( %object, strlen( "button" ), 1000 );
  303.             return( %mods @ "joystick" @ ( %instance + 1 ) );
  304.         }
  305.         else
  306.        { 
  307.           %pos = strstr( %action, "pov" );
  308.          if ( %pos != -1 )
  309.          {
  310.             %wordCount = getWordCount( %action );
  311.             %mods = %wordCount > 1 ? getWords( %action, 0, %wordCount - 2 ) @ " " : "";
  312.             %object = getWord( %action, %wordCount - 1 );
  313.             switch$ ( %object )
  314.             {
  315.                case "upov":   %object = "POV1 up";
  316.                case "dpov":   %object = "POV1 down";
  317.                case "lpov":   %object = "POV1 left";
  318.                case "rpov":   %object = "POV1 right";
  319.                case "upov2":  %object = "POV2 up";
  320.                case "dpov2":  %object = "POV2 down";
  321.                case "lpov2":  %object = "POV2 left";
  322.                case "rpov2":  %object = "POV2 right";
  323.                default:       %object = "??";
  324.             }
  325.             return( %mods @ %object );
  326.          }
  327.          else
  328.             error( "Unsupported Joystick input object passed to getDisplayMapName!" );
  329.       }
  330.     }
  331.         
  332.     return( "??" );        
  333. }
  334.  
  335. function buildFullMapString( %index )
  336. {
  337.    %name       = $RemapName[%index];
  338.    %cmd        = $RemapCmd[%index];
  339.  
  340.     %temp = moveMap.getBinding( %cmd );
  341.    %device = getField( %temp, 0 );
  342.    %object = getField( %temp, 1 );
  343.    if ( %device !$= "" && %object !$= "" )
  344.        %mapString = getMapDisplayName( %device, %object );
  345.    else
  346.       %mapString = "";
  347.  
  348.     return( %name TAB %mapString );
  349. }
  350.  
  351. function OptRemapList::fillList( %this )
  352. {
  353.     %this.clear();
  354.    for ( %i = 0; %i < $RemapCount; %i++ )
  355.       %this.addRow( %i, buildFullMapString( %i ) );
  356. }
  357.  
  358. //------------------------------------------------------------------------------
  359. function OptRemapList::doRemap( %this )
  360. {
  361.     %selId = %this.getSelectedId();
  362.    %name = $RemapName[%selId];
  363.  
  364.     OptRemapText.setValue( "REMAP \"" @ %name @ "\"" );
  365.     OptRemapInputCtrl.index = %selId;
  366.     Canvas.pushDialog( RemapDlg );
  367. }
  368.  
  369. //------------------------------------------------------------------------------
  370. function redoMapping( %device, %action, %cmd, %oldIndex, %newIndex )
  371. {
  372.     //%actionMap.bind( %device, %action, $RemapCmd[%newIndex] );
  373.     moveMap.bind( %device, %action, %cmd );
  374.     OptRemapList.setRowById( %oldIndex, buildFullMapString( %oldIndex ) );
  375.     OptRemapList.setRowById( %newIndex, buildFullMapString( %newIndex ) );
  376. }
  377.  
  378. //------------------------------------------------------------------------------
  379. function findRemapCmdIndex( %command )
  380. {
  381.     for ( %i = 0; %i < $RemapCount; %i++ )
  382.     {
  383.         if ( %command $= $RemapCmd[%i] )
  384.             return( %i );            
  385.     }
  386.     return( -1 );    
  387. }
  388.  
  389. function OptRemapInputCtrl::onInputEvent( %this, %device, %action )
  390. {
  391.     //error( "** onInputEvent called - device = " @ %device @ ", action = " @ %action @ " **" );
  392.     Canvas.popDialog( RemapDlg );
  393.  
  394.     // Test for the reserved keystrokes:
  395.     if ( %device $= "keyboard" )
  396.     {
  397.       // Cancel...
  398.       if ( %action $= "escape" )
  399.       {
  400.          // Do nothing...
  401.            return;
  402.       }
  403.     }
  404.     
  405.    %cmd  = $RemapCmd[%this.index];
  406.    %name = $RemapName[%this.index];
  407.  
  408.     // First check to see if the given action is already mapped:
  409.     %prevMap = moveMap.getCommand( %device, %action );
  410.    if ( %prevMap !$= %cmd )
  411.    {
  412.        if ( %prevMap $= "" )
  413.        {
  414.          moveMap.bind( %device, %action, %cmd );
  415.            OptRemapList.setRowById( %this.index, buildFullMapString( %this.index ) );
  416.        }
  417.        else
  418.        {
  419.          %mapName = getMapDisplayName( %device, %action );
  420.            %prevMapIndex = findRemapCmdIndex( %prevMap );
  421.            if ( %prevMapIndex == -1 )
  422.                MessageBoxOK( "REMAP FAILED", "\"" @ %mapName @ "\" is already bound to a non-remappable command!" );
  423.            else
  424.          {
  425.             %prevCmdName = $RemapName[%prevMapIndex];
  426.                MessageBoxYesNo( "WARNING", 
  427.                    "\"" @ %mapName @ "\" is already bound to \"" 
  428.                        @ %prevCmdName @ "\"!\nDo you want to undo this mapping?", 
  429.                    "redoMapping(" @ %device @ ", \"" @ %action @ "\", \"" @ %cmd @ "\", " @ %prevMapIndex @ ", " @ %this.index @ ");", "" );
  430.          }
  431.            return;
  432.        }
  433.    }
  434. }
  435.  
  436. // Audio 
  437. function OptAudioUpdate()
  438. {
  439.    // set the driver text
  440.    %text =   "Vendor: " @ alGetString("AL_VENDOR") @
  441.            "\nVersion: " @ alGetString("AL_VERSION") @
  442.            "\nRenderer: " @ alGetString("AL_RENDERER") @
  443.            "\nExtensions: " @ alGetString("AL_EXTENSIONS");
  444.    OptAudioInfo.setText(%text);
  445.  
  446. }
  447.  
  448.  
  449. // Channel 0 is unused in-game, but is used here to test master volume.
  450.  
  451. new AudioDescription(AudioChannel0)
  452. {
  453.    volume   = 1.0;
  454.    isLooping= false;
  455.    is3D     = false;
  456.    type     = 0;
  457. };
  458.  
  459. new AudioDescription(AudioChannel1)
  460. {
  461.    volume   = 1.0;
  462.    isLooping= false;
  463.    is3D     = false;
  464.    type     = 1;
  465. };
  466.  
  467. new AudioDescription(AudioChannel2)
  468. {
  469.    volume   = 1.0;
  470.    isLooping= false;
  471.    is3D     = false;
  472.    type     = 2;
  473. };
  474.  
  475. new AudioDescription(AudioChannel3)
  476. {
  477.    volume   = 1.0;
  478.    isLooping= false;
  479.    is3D     = false;
  480.    type     = 3;
  481. };
  482.  
  483. new AudioDescription(AudioChannel4)
  484. {
  485.    volume   = 1.0;
  486.    isLooping= false;
  487.    is3D     = false;
  488.    type     = 4;
  489. };
  490.  
  491. new AudioDescription(AudioChannel5)
  492. {
  493.    volume   = 1.0;
  494.    isLooping= false;
  495.    is3D     = false;
  496.    type     = 5;
  497. };
  498.  
  499. new AudioDescription(AudioChannel6)
  500. {
  501.    volume   = 1.0;
  502.    isLooping= false;
  503.    is3D     = false;
  504.    type     = 6;
  505. };
  506.  
  507. new AudioDescription(AudioChannel7)
  508. {
  509.    volume   = 1.0;
  510.    isLooping= false;
  511.    is3D     = false;
  512.    type     = 7;
  513. };
  514.  
  515. new AudioDescription(AudioChannel8)
  516. {
  517.    volume   = 1.0;
  518.    isLooping= false;
  519.    is3D     = false;
  520.    type     = 8;
  521. };
  522.  
  523. $AudioTestHandle = 0;
  524.  
  525. function OptAudioUpdateMasterVolume(%volume)
  526. {
  527.    if (%volume == $pref::Audio::masterVolume)
  528.       return;
  529.    alxListenerf(AL_GAIN_LINEAR, %volume);
  530.    $pref::Audio::masterVolume = %volume;
  531.    if (!alxIsPlaying($AudioTestHandle))
  532.    {
  533.       $AudioTestHandle = alxCreateSource("AudioChannel0", expandFilename("~/data/sound/testing.ogg"));
  534.       alxPlay($AudioTestHandle);
  535.    }
  536. }
  537.  
  538. function OptAudioUpdateChannelVolume(%channel, %volume)
  539. {
  540.    if (%channel < 1 || %channel > 8)
  541.       return;
  542.          
  543.    if (%volume == $pref::Audio::channelVolume[%channel])
  544.       return;
  545.  
  546.    alxSetChannelVolume(%channel, %volume);
  547.    $pref::Audio::channelVolume[%channel] = %volume;
  548.    if (!alxIsPlaying($AudioTestHandle))
  549.    {
  550.       $AudioTestHandle = alxCreateSource("AudioChannel"@%channel, expandFilename("~/data/sound/testing.ogg"));
  551.       alxPlay($AudioTestHandle);
  552.    }
  553. }
  554.  
  555.  
  556. function OptAudioDriverList::onSelect( %this, %id, %text )
  557. {
  558.    if (%text $= "")
  559.       return;
  560.    
  561.    if ($pref::Audio::driver $= %text)
  562.       return;
  563.  
  564.    $pref::Audio::driver = %text;
  565.    OpenALInit();
  566. }
  567.